﻿@{
    Layout = "~/Views/Shared/_detail.cshtml";
    if (false)
    {
        <script src="~/LiberUI/Scripts/jquery.js"></script>
        <script src="~/LiberUI/Scripts/LiberUI.Base.js"></script>
        <script src="~/LiberUI/Scripts/LiberUI.js"></script>
        <script src="~/LiberUI/Scripts/LiberUI.Action.js"></script>
    }
    <link href="/SiteUI/Sale/DeliveryBill.css" rel="stylesheet" />
}
<title>发货单</title>

<div id="pagePath">
    <a class="strong" href="/Sale/Delivery">销售：发货管理</a>&nbsp;>&nbsp;<a href="#">发货单</a>
</div>

<div class="row" id="orderHead">
    <div class="col-lg-4">
        <h4>交易编号：<a class="LinkTo" id="oh-id">00001</a></h4>
    </div>
    <div class="col-lg-4">
        &nbsp;
    </div>
    <div class="col-lg-4">
        <h4>状态:<span id="oh-status" class="pendding"><i>未确认</i></span></h4>
    </div>
    <div class="col-lg-12">
        <div class="row" id="orderStatusEx">
            <div class="col-lg-4">
                <h5>交付进度</h5>
                <div id="orderDelivery">
                    -
                </div>
            </div>
        </div>
    </div>
    
</div>

<!--订单详情-->
<div class="InfoSection row expand">
    <div class="InfoSectionTitle">
        交易信息
        <i class="soicon "></i>
    </div>
    <div class="InfoSectionBody col-lg-12" id="tradeInfo">
        <div class="row ti-head">
            <div class="col-lg-4">
                <h5>买方信息</h5>
            </div>
            <div class="col-lg-4">
                <h5>交付信息</h5>
            </div>
            <div class="col-lg-4">
                <h5>支付和发票信息</h5>
            </div>
        </div>
        <div class="row ti-body">
            <div class="col-lg-4">
                <div class="DataField">
                    <span class="df-title">采&nbsp;&nbsp;购&nbsp;&nbsp;商：</span>
                    {{#if(d.client_realname){ }}
                    <span class="df-value"><a href="/Company/Portal?oid={{d.client_idstr}}">{{d.client_realname}}</a></span>
                    {{#}else{ }}
                    <span class="df-value"><a href="#">{{d.src_client}}</a></span>
                    {{#} }}
                </div>
                <div class="DataField">
                    <span class="df-title">联&nbsp;&nbsp;系&nbsp;&nbsp;人：</span>
                    {{#if(d.buyer_realname){ }}
                    <span class="df-value"><a href="#">{{d.buyer_realname}}</a></span>
                    {{#}else{ }}
                    <span class="df-value"><a href="#">{{d.src_buyer}}</a></span>
                    {{#} }}
                </div>
                <div class="DataField">
                    <span class="df-title">联系方式：</span>
                    <span class="df-value">{{d.buyer_phone}}</span>
                </div>
            </div>
            <div class="col-lg-4">
                <div class="DataField">
                    <span class="df-title">收&nbsp;&nbsp;货&nbsp;&nbsp;人：</span>
                    <span class="df-value">
                        <span>{{d.consignee_displayname}}</span>
                        <span>{{d.consignee_phone}}</span>
                    </span>
                </div>
                <div class="DataField">
                    <span class="df-title">交付方式：</span>
                    <span class="df-value">{{d.deliverymode}}</span>
                </div>
                <div class="DataField">
                    <span class="df-title">送货地址：</span>
                    <span class="df-value">{{d.src_dlvaddress}}</span>
                </div>
                <div class="DataField">
                    <span class="df-title">送货时间：</span>
                    {{#if(d._urgent){ }}
                    <span class="df-value urgent" title="交货日期已临近，请注意跟进">{{d._dlvDate}}<i class="icon-erroroutline"></i></span>
                    {{#}else{ }}
                    <span class="df-value">{{d._dlvDate}}</span>
                    {{#} }}
                </div>
                <div class="DataField">
                    <span class="df-title">质保条件</span>
                    <span class="df-value">{{d.qualityguarantee}}</span>
                </div>
            </div>
            <div class="col-lg-4">
                <div class="DataField">
                    <span class="df-title">支付方式：</span>
                    <span class="df-value">{{d.settlement}}</span>
                </div>
                <div class="DataField">
                    <span class="df-title">发票抬头：</span>
                    <span class="df-value">{{d.invoiceheading}}</span>
                </div>
                <div class="DataField">
                    <span class="df-title">发票类型：</span>
                    <span class="df-value">增值税发票</span>
                </div>
                <div class="DataField">
                    <span class="df-title">税&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;率：</span>
                    <span class="df-value">17%</span>
                </div>
                <div class="DataField">
                    <span class="df-title">发票内容：</span>
                    <span class="df-value">明细</span>
                </div>
            </div>
        </div>
        <div class="row">
            <h5>其他信息</h5>
            {{#if(d.src_orderserial){ }}
            <div class="DataField">
                <span class="df-title">客户订单：</span>
                <span class="df-value">{{d.src_orderserial}}{{d.src_orderversion}}</span>
            </div>
            {{#} }}
            <div class="DataField">
                <span class="df-title">备&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;注：</span>
                <span class="df-value">{{d.memo}}</span>
            </div>
        </div>
    </div>
</div>

<!--订单明细-->
<div class="InfoSection row expand" id="orderItems">
    <div class="InfoSectionTitle col-lg-12">
        发货明细
        <i class="soicon "></i>
    </div>
    <div class="InfoSectionBody col-lg-12">
        <div class="gridtable modenStyle">
            <div class="grid-row headrow">
                <div class="grid-col" style="width:25%">产品</div>
                <div class="grid-col" style="width:35%">型号&规格</div>
                <div class="grid-col" style="width:15%">数量</div>
                <div class="grid-col" style="width:12.5%">累计已发</div>
                <div class="grid-col end" style="width:12.5%">本次发货</div>
            </div>
            <div class="grid-body">
                <div class="grid-row order-item-tpl">
                    <div class="grid-col order-item-product" style="width:25%"></div>
                    <div class="grid-col order-item-describe" style="width:35%"></div>
                    <div class="grid-col order-item-count" style="width:15%"></div>
                    <div class="grid-col order-item-deliveried" style="width:12.5%"></div>
                    <div class="grid-col end order-item-todelivery"style="width:12.5%">
                        <input />
                    </div>
                </div>
            </div>
        </div>
    </div>   
</div>
<div class="row">
    <div class="col-lg-2 col-lg-offset-10 button" id="btnReceipt">收货确认</div>
</div>

<script src="/LiberUI/Scripts/laytpl.js"></script>
<script src="/SiteUI/res_sobiz.js"></script>
<script>
    var order={}
    var ViewDB = {
        tplOrderInfo:null,
        btnDelivery:null,
        GetOrderEnd: function (rtn) {
            if (rtn.IsPositive) {
                order = rtn.Data;
                //#region 处理订单状态信息
                $("#oh-id").vl(order.idstr);
                $("#oh-status").addClass(order.status);
                $("#oh-status").vl("<i></i>" + res_sobiz.var.Sale[order.status]);
                order.buyer_phone = order.buyer_phone || "-";
                order.buyer_email = order.buyer_email || "-";
                order.saler_phone = order.saler_phone || "-";
                order.saler_email = order.saler_email || "-";
                order.consignee_displayname = order.src_consignee || order.consignee_realname;
                order.consignee_phone = order.consignee_phone || order.src_consigneephone;
                order._dlvDate = new Date(order.src_deliverydate || order.deliverydate).toString();
                order._urgent = daysBetween(new Date(order.src_deliverydate || order.deliverydate).toString(), new Date().toString()) < 5;
                //#endregion

                var ti = ViewDB.tplOrderInfo.render(order);
                $("#tradeInfo").append(ti).fadeIn();

                ViewDB.renderOrderMX();
            }
        },
        GetDeliveryEnd:function(rtn){
            if (rtn.IsPositive) {

            }
        },
        renderOrderMX:function(){
            //#region 处理订单明细
            if (order.OrderMX) {
                var tpl = $(".order-item-tpl").eq(0);
                order.OrderMX.forEach(function (i) {
                    var row = tpl.clone();
                    var cols = row.children(".grid-col");
                    var b = $("<div class='DataField'>");
                    b.append($("<span class='df-title'>品牌：</span>"));
                    b.append($("<span class='df-value'>").vl(i.brand || '-'));

                    var p = $("<div class='DataField'>");
                    p.append($("<span class='df-title'>产品：</span>"));
                    p.append($("<span class='df-value'>").vl(i.product || '-'));

                    var c = $("<div class='DataField'>");
                    c.append($("<span class='df-title'>编码：</span>"));
                    c.append($("<span class='df-value'>").vl(i.src_code || '-'));

                    var m = $("<div class='DataField'>");
                    m.append($("<span class='df-title'>型号：</span>"));
                    m.append($("<span class='df-value'>").vl(i.model || '-'));

                    var s = $("<div class='DataField'>");
                    s.append($("<span class='df-title'>规格：</span>"));
                    s.append($("<span class='df-value'>").vl(i.src_specification || '-'));

                    cols.eq(0).append(b).append(p).append(c);
                    cols.eq(1).append(m).append(s);
                    cols.eq(2).vl(i.count + "(" + i.unit + ")");
                    cols.eq(3).vl(i.totalDeliverid);
                    cols.eq(4).children("input").vl(0).attr("enabled",false);
                    row.appendTo(".grid-body").show();

                    i.$row = row;
                });
            }
            //#endregion
        },
        onInsecClick: function (ev) {
            $(this).parent(".InfoSection").toggleClass("expand");
        },
        Delivery: function (ev) {
            //收集数据并校验
            var dlvOrder = {
                arrivaltime :$("#dlvArrivalTime>input").vl(),
                dlvorderno : $("#dlvDeliveryOrder>input").vl(),
                dlvDeliverier :$("#dlvDeliveryMan>input").vl(),
                orderid : order.idstr
            }
            var dlvMx = [];
            order.OrderMX.forEach(function (i) {
                dlvThis = i.$row.children(".grid-col").eq(3);
                var dlvCount = parseFloat(dlvThis.children("input").vl());
                dlvMx.push(
                    {
                        "ordermxidstr": i.idstr,
                        "todelivery":dlvCount
                    }
                );
            })
            //发送
            if (flagErr) {
                flagErr = false;
                return;
            }
            $.post("/Sale/NewDelivery", { "dlvMX": GetXML({"item": dlvMx, "deliveryOrder": dlvOrder }) }, function () { window.location="/Sale/DeliveryBillPrnt?oid="+order.idstr; });
        }
    }

    $(function () {
        var oid = getUrlParam("oid");
        $.getJSON("/Sale/GetDelivery", { "oid": oid }, ViewDB.GetDeliveryEnd);

        $(".InfoSectionTitle").on("click", ViewDB.onInsecClick);
        ViewDB.tplOrderInfo = laytpl($("#tradeInfo")[0].innerHTML);
        $("#tradeInfo").vl("");
    })
</script>

